<?php
session_start();
?>
<table width='300' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>
    <tr>
        <?php
        // check if user is logged or not 
        if (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn']) {
            //if yes, show log out form
            ?>
        <form name='form1' method='post' action="logout.php">
            <td>
                <table width='100%' border='0' cellpadding='3' cellspacing='1' bgcolor='#FFFFFF'>
                    <tr>
                        <td align='center' colspan='3'><strong>You are logged in. </strong></td>
                    </tr>
                    <tr>
                        <td align='center'><input type='submit' name='Submit' value='Logout'></td>
                    </tr>
                </table>
                <?php
            } else {
                // if not logged show login form
                ?>
                <form name='form1' method='post' action="checkpass.php">
                    <td>
                        <table width='100%' border='0' cellpadding='3' cellspacing='1' bgcolor='#FFFFFF'>
                            <tr>
                                <td colspan='3'><strong>Member Login </strong></td>
                            </tr>
                            <tr>
                                <td width='78'>Username</td>
                                <td width='6'>:</td>
                                <td width='294'><input name='username' type='text' id='username'></td>
                            </tr>
                            <tr>
                                <td>Password</td>
                                <td>:</td>
                                <td><input name='password' type='password' id='password'></td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td><input type='submit' name='Submit' value='Login'></td>
                            </tr>
                            <?php
                            if (isset($_SESSION['loggedIn']) && !$_SESSION['loggedIn']) {
                                echo '<font color="red"> Incorrect username/password. Please, try again.</font>';
                            }
                            ?>
                        </table>
                    </td>
                </form>
                </tr>
                </table>
                <?php
            }
            ?>

